/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package herramientas;

import java.security.MessageDigest;

/**
 *
 * @author pimpa
 */
public class sha256 {

    private MessageDigest md;

    public sha256() {
        try {
            md = MessageDigest.getInstance("SHA-256");
        } catch (Exception e) {
            System.out.println("PROBLEM");
        }
    }

    public String aplicarSHA256(String s) {
        try {
            md.update(s.getBytes("UTF-8")); // Change this to "UTF-16" if needed
            byte[] digest = md.digest();
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < digest.length; i++) {
                sb.append(Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1));
            }
            return sb.toString();

        } catch (Exception e) {
            System.out.println("PROBLEM");
            return e.getMessage();
        }
    }
}
